package sysAuth

import initConfig.SysInitData

class SysUserRoles {

    SysUsers user ;
    SysRoles role;
    static constraints = {
        user(nullable: false,blank: false,unique: "role")
        role(nullable: false,blank: false)
    }
    static mapping = {
        version false
    }

    static init(){
        if(SysUserRoles.count !=0){
            return
        }

        def adminUser = SysUsers.findAllByUserNo(SysInitData.SYS_ADMIN)
        SysRoles.findAllByRoleNoInList(SysInitData.AdminRole.keySet().toList()).each {
            new SysUserRoles(user: adminUser,role: it).save(flush: true)
        }

        def testUser = SysUsers.findByUserNo(SysInitData.TEST_NAME)
        SysRoles.findAllByRoleNo(SysInitData.TEST_NAME).each {
            new SysUserRoles(user: testUser,role: it).save(flush: true)
        }
    }
}
